package _interview100;


import _object.ListNode;

/**
 * 2. 两数相加
 */
public class No2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode answer = new ListNode(-1), cur = new ListNode(-1);
        answer.next = cur;
        int curVal = 0;
        while (l1 != null || l2 != null) {
            if (l1 != null) {
                curVal += l1.val;
                l1 = l1.next;
            }
            if (l2 != null) {
                curVal += l2.val;
                l2 = l2.next;
            }
            cur.next = new ListNode(curVal % 10);
            curVal /= 10;
            cur = cur.next;
        }
        if (curVal != 0) cur.next = new ListNode(1);
        return answer.next.next;
    }
}
